package org.makcro.sms.services.chat.web.client.widgets.bulk;

import org.makcro.sms.services.chat.web.client.AppEvents.BulkEvents;
import org.makcro.sms.services.chat.web.shared.dto.HistoryItemDto;

import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.grid.Grid;

public class SendBulkMenuItemSelectionListener extends SelectionListener<MenuEvent> {
	/**
	 * Grid instance that context menu is associated to
	 */
	private Grid<HistoryItemDto>	grid;
	
	
	public SendBulkMenuItemSelectionListener(Grid<HistoryItemDto> grid) {
		this.grid = grid;
	}
	@Override
	public void componentSelected(MenuEvent ce) {
		// get grids selected item
		HistoryItemDto historyItemDto = grid.getSelectionModel().getSelectedItem();
		if(historyItemDto != null){
			AppEvent appEvent = new AppEvent( BulkEvents.SEND_BULK_REQUESTED, historyItemDto );
			
			Dispatcher.get().dispatch( appEvent );
		}

	}

}
